﻿#!/usr/bin/env python
# ------------------------------------------------------------------------------
#
# Main module, from where to run the sim
#
# Copyright (c) 2012 Fernando Garcia Huerta
# nanomuelle@gmail.com
#
#    This file is part of SimCell
#
#    SimCell is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    SimCell is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with SimAnim.  If not, see <http://www.gnu.org/licenses/>.
#
# ------------------------------------------------------------------------------

__author__    = "$Author$"
__revision__  = "$Revision$"
__date__      = "$Date: 16 Jan 2012 $"
__copyright__ = "2012 nanomuelle.com"
__contact__   = "http://blog.nanomuelle.com"

import os
import sys
import random
# import pprint

import pygame
from pygame.locals import *

from config import * #SCREENRECT, SCREENSCALE
# from resource_manager import rm

from simcell.world.world import World



def main(argv=None):
    os.environ["SDL_VIDEO_CENTERED"] = "1"
    
    pygame.init()
    
    winstyle = 0  # |FULLSCREEN
    bestdepth = pygame.display.mode_ok((SCREENRECT.width * SCREENSCALE, 
                                        SCREENRECT.height * SCREENSCALE), winstyle, 32)
    
    screen = pygame.display.set_mode((SCREENRECT.width * SCREENSCALE,
                                      SCREENRECT.height * SCREENSCALE), winstyle, bestdepth)

    background = pygame.Surface(screen.get_size())
    background = background.convert()
    background.fill((5, 5, 5))
    centerx = background.get_width()/2
  
    w = World(INITIAL_NUM_ORGANISM, INITIAL_ADN_LENGHT)
    for i in range(2500):
    
        pygame.display.flip()
        
        w.cicle()

        screen.blit(background, (0, 0))
        
        if pygame.font:
            font = pygame.font.Font(None, 20)
            infocicle = "Ciclo: %d" % w.cicleNum
            textcicle = font.render(infocicle, 1, (255, 255, 10))
            
            infoorganisms = " Organisms: %d" % len(w.population)
            textorganisms = font.render(infoorganisms, 1, (255, 255, 10))
            
            screen.blit(textcicle, (0,0))
            screen.blit(textorganisms, (100,0))
            
        for organism in w.population:
          pos = organism.pos
          for cell in organism.cells:
            size = cell.proteinBag.getVolume() / 1000
            pygame.draw.circle(screen, (128, 128, 255), (int(pos[0]), int(pos[1])), size)
            pos = (pos[0] + size, pos[1])
          
        
    w.printPopulation()
#  os.system("PAUSE")  

if __name__ == "__main__":
    sys.exit(main())
